package com.sjzd.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sjzd.server.pojo.Employee;
import com.sjzd.server.mapper.EmployeeMapper;
import com.sjzd.server.pojo.RespPageBean;
import com.sjzd.server.service.IEmployeeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sjzd
 * @since 2021-02-21
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public RespPageBean page(Employee employee, LocalDate[] beginDateScope, Integer curPage, Integer pageSize) {
        Page<Employee> employeePage = new Page<>(curPage, pageSize);
        RespPageBean respPageBean = new RespPageBean();
        IPage<Employee> page = employeeMapper.page(employee, beginDateScope,employeePage);
        respPageBean.setTotal(page.getTotal());
        respPageBean.setObj(page.getRecords());
        respPageBean.setCurPage(page.getCurrent());
        respPageBean.setPageSize(page.getSize());
        return respPageBean;
    }

    @Override
    public String getWorkID() {
        List<Map<String, Object>> maps = employeeMapper.selectMaps(new QueryWrapper<Employee>().select("max(workID)"));
        return String.format("%08d",Integer.parseInt(maps.get(0).get("max(workID)").toString()) + 1);
    }

    @Override
    public List<Employee> getEmployee(Integer id) {
        return employeeMapper.getEmployee(id);
    }
}
